package com.itheima.config;

import com.itheima.interceptor.MyInterceptor;
import com.itheima.interceptor.MyInterceptor2;
import com.itheima.interceptor.MyInterceptor3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * Description:
 *
 * @author codermao
 * @date 2023/11/8 15:15
 */
@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {
    @Autowired
    private MyInterceptor myInterceptor;

    @Autowired
    private MyInterceptor2 myInterceptor2;

    @Autowired
    private MyInterceptor3  myInterceptor3;
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
        registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/");
    }

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    protected void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) {
        registry.addInterceptor(myInterceptor).addPathPatterns("/books","/books/*");
        registry.addInterceptor(myInterceptor2).addPathPatterns("/books","/books/*");
        registry.addInterceptor(myInterceptor3).addPathPatterns("/books","/books/*");
    }
}